from fastapi import APIRouter, Body

from common.pkg.fastapi_util import cbv
from core.view import AdminBaseView
from schema.req_schema.currency_req_schema import AddNewCurrencyModel, UpdateCurrencyRequestModel
from schema.resp_schema.currency_schema import ListCurrencyResponseModel, AddNewCurrencyResponseModel
from service.currency_service import CurrencyService

router = APIRouter(prefix="/currency")


@cbv(router)
class CurrencyView(AdminBaseView):

    @router.get("", description="获取当前所有支持的币种信息", response_model=ListCurrencyResponseModel)
    async def get_currencys(self):
        cs = CurrencyService(self.mgw, self.redis)
        ok, data_or_code = await cs.get_currency_list()
        return self.unpack_response(ok, data_or_code)

    @router.post("", description="新增币种信息", response_model=AddNewCurrencyResponseModel)
    async def add_currency(self, currency_model: AddNewCurrencyModel = Body(...)):
        cs = CurrencyService(self.mgw, self.redis)
        ok, data_or_code = await cs.add_new_currency(currency_model)
        return self.unpack_response(ok, data_or_code)

    @router.put("/{code:str}", description="根据code修改币种信息")
    async def update_currency(self,
                              code: str,
                              req_model: UpdateCurrencyRequestModel = Body(...)):
        ...

    @router.delete("/{code:str}", description="根据code删除币种")
    async def update_currency(self,
                              code: str):
        ...
